<!-- 下拉选择组件 -->
<template>
  <div class="GfSelect">
    <div :class="['label', { required: componentData.required }]">
      {{ componentData.label }}
    </div>
    <div class="value">
      <a-select
        v-model:value="mValue"
        style="width: 120px"
        :options="componentData.options"
      ></a-select>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, watch } from 'vue'

export default defineComponent({
  name: 'GfSelect',
  props: ['value', 'componentData'],
  emits: ['update:value'],
  setup(props, context) {
    let mValue = ref(false)
    let executeOnce = false
    watch(
      () => props.value,
      (newVal) => {
        if (executeOnce || newVal === undefined) return
        executeOnce = true
        mValue.value = newVal
      },
      {
        immediate: true,
        deep: true
      }
    )
    watch(mValue, (newVal) => {
      context.emit('update:value', newVal)
    })

    return {
      mValue
    }
  }
})
</script>

<style lang="scss" scoped>
.GfSelect {
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .label {
    font-size: 14px;
    color: rgba($color: #000000, $alpha: 0.85);
    &.required::before {
      content: '*';
      color: #ff4d4f;
      font-size: 14px;
      margin-right: 4px;
    }
  }
}
</style>
